export default function matchForeColor(
  backgroundColor,
  alpha = -1,
  threshold = 96
) {
  let r = parseInt(backgroundColor.substring(1, 3), 16);
  let g = parseInt(backgroundColor.substring(3, 5), 16);
  let b = parseInt(backgroundColor.substring(5, 7), 16);
  let brightness = (r * 299 + g * 587 + b * 114) / 1000;
  return alpha == -1
    ? brightness > threshold
      ? "#000000"
      : "#ffffff"
    : brightness > threshold
    ? "rgba(0,0,0," + alpha + ")"
    : "rgba(255,255,255," + alpha + ")";
}
